package com.hirsi.module.developer.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.hirsi.common.core.annotation.IgnoreAccessTokenValid;
import com.hirsi.common.core.annotation.RequestBodyParam;
import com.hirsi.common.core.vo.param.PageParam;
import com.hirsi.common.core.vo.result.PageResult;
import com.hirsi.module.developer.mapper.DeveloperMapper;
import com.hirsi.module.developer.service.DeveloperService;
import com.hirsi.module.developer.vo.param.AuditDeveloperParam;
import com.hirsi.module.developer.vo.param.QueryDeveloperApplyParam;
import com.hirsi.module.developer.vo.param.QueryDeveloperParam;
import com.hirsi.module.developer.vo.result.DeveloperApplyResult;
import com.hirsi.module.developer.vo.result.DeveloperResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "开发者管理")
@ApiSupport(order = 20)
@RestController
@RequestMapping("rest/v1/developer")
public class DeveloperController {

    @Autowired
    private DeveloperMapper developerMapper;

    @Autowired
    private DeveloperService developerService;

    @IgnoreAccessTokenValid
    @ApiOperation("分页查询开发者列表")
    @ApiOperationSupport(order = 1)
    @GetMapping("query")
    public PageResult<DeveloperResult> query(PageParam page, @Validated QueryDeveloperParam param) {
        return PageResult.parse(developerMapper.selectDeveloperResult(page.pager(), param));
    }

    @IgnoreAccessTokenValid
    @ApiOperation("分页查询开发者申请列表")
    @ApiOperationSupport(order = 10)
    @GetMapping("apply/query")
    public PageResult<DeveloperApplyResult> queryApply(PageParam page, @Validated QueryDeveloperApplyParam param) {
        return PageResult.parse(developerMapper.selectDeveloperApplyResult(page.pager(), param));
    }

    @IgnoreAccessTokenValid
    @ApiOperation("审核开发者申请")
    @ApiOperationSupport(order = 11)
    @PostMapping("apply/audit")
    public void auditApply(@RequestBodyParam @Validated AuditDeveloperParam param) {
        developerService.auditApply(param);
    }
}
